using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the PlanningLog class.
	/// </summary>
	[Serializable]
	public partial class PlanningLogCollection : ActiveList<PlanningLog, PlanningLogCollection> 
	{	   
		public PlanningLogCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the PlanningLog table.
	/// </summary>
	[Serializable]
	public partial class PlanningLog : ActiveRecord<PlanningLog>
	{
		#region .ctors and Default Settings
		
		public PlanningLog()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public PlanningLog(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public PlanningLog(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public PlanningLog(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("PlanningLog", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarPlanningLogID = new TableSchema.TableColumn(schema);
				colvarPlanningLogID.ColumnName = "PlanningLogID";
				colvarPlanningLogID.DataType = DbType.Int32;
				colvarPlanningLogID.MaxLength = 0;
				colvarPlanningLogID.AutoIncrement = true;
				colvarPlanningLogID.IsNullable = false;
				colvarPlanningLogID.IsPrimaryKey = true;
				colvarPlanningLogID.IsForeignKey = true;
				colvarPlanningLogID.IsReadOnly = false;
				colvarPlanningLogID.DefaultSetting = @"";
				
					colvarPlanningLogID.ForeignKeyTableName = "PlanningLog";
				schema.Columns.Add(colvarPlanningLogID);
				
				TableSchema.TableColumn colvarMediaCode = new TableSchema.TableColumn(schema);
				colvarMediaCode.ColumnName = "MediaCode";
				colvarMediaCode.DataType = DbType.Int32;
				colvarMediaCode.MaxLength = 0;
				colvarMediaCode.AutoIncrement = false;
				colvarMediaCode.IsNullable = true;
				colvarMediaCode.IsPrimaryKey = false;
				colvarMediaCode.IsForeignKey = true;
				colvarMediaCode.IsReadOnly = false;
				colvarMediaCode.DefaultSetting = @"";
				
					colvarMediaCode.ForeignKeyTableName = "Medium";
				schema.Columns.Add(colvarMediaCode);
				
				TableSchema.TableColumn colvarCarriers = new TableSchema.TableColumn(schema);
				colvarCarriers.ColumnName = "Carriers";
				colvarCarriers.DataType = DbType.String;
				colvarCarriers.MaxLength = 500;
				colvarCarriers.AutoIncrement = false;
				colvarCarriers.IsNullable = true;
				colvarCarriers.IsPrimaryKey = false;
				colvarCarriers.IsForeignKey = false;
				colvarCarriers.IsReadOnly = false;
				colvarCarriers.DefaultSetting = @"";
				colvarCarriers.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCarriers);
				
				TableSchema.TableColumn colvarBillboardstype = new TableSchema.TableColumn(schema);
				colvarBillboardstype.ColumnName = "Billboardstype";
				colvarBillboardstype.DataType = DbType.String;
				colvarBillboardstype.MaxLength = 500;
				colvarBillboardstype.AutoIncrement = false;
				colvarBillboardstype.IsNullable = true;
				colvarBillboardstype.IsPrimaryKey = false;
				colvarBillboardstype.IsForeignKey = false;
				colvarBillboardstype.IsReadOnly = false;
				colvarBillboardstype.DefaultSetting = @"";
				colvarBillboardstype.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBillboardstype);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = false;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				colvarDateAdded.DefaultSetting = @"";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = false;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				colvarDateModified.DefaultSetting = @"";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("PlanningLog",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("PlanningLogID")]
		public int PlanningLogID 
		{
			get { return GetColumnValue<int>("PlanningLogID"); }

			set { SetColumnValue("PlanningLogID", value); }

		}

		  
		[XmlAttribute("MediaCode")]
		public int? MediaCode 
		{
			get { return GetColumnValue<int?>("MediaCode"); }

			set { SetColumnValue("MediaCode", value); }

		}

		  
		[XmlAttribute("Carriers")]
		public string Carriers 
		{
			get { return GetColumnValue<string>("Carriers"); }

			set { SetColumnValue("Carriers", value); }

		}

		  
		[XmlAttribute("Billboardstype")]
		public string Billboardstype 
		{
			get { return GetColumnValue<string>("Billboardstype"); }

			set { SetColumnValue("Billboardstype", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime DateAdded 
		{
			get { return GetColumnValue<DateTime>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime DateModified 
		{
			get { return GetColumnValue<DateTime>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		
		#endregion
		
		
		#region PrimaryKey Methods
		
		public Adex.PlanningLogCollection ChildPlanningLogRecords()
		{
			return new Adex.PlanningLogCollection().Where(PlanningLog.Columns.PlanningLogID, PlanningLogID).Load();
		}

		#endregion
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Medium ActiveRecord object related to this PlanningLog
		/// 
		/// </summary>
		public Adex.Medium Medium
		{
			get { return Adex.Medium.FetchByID(this.MediaCode); }

			set { SetColumnValue("MediaCode", value.MediaCode); }

		}

		
		
		/// <summary>
		/// Returns a PlanningLog ActiveRecord object related to this PlanningLog
		/// 
		/// </summary>
		public Adex.PlanningLog ParentPlanningLog
		{
			get { return Adex.PlanningLog.FetchByID(this.PlanningLogID); }

			set { SetColumnValue("PlanningLogID", value.PlanningLogID); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int? varMediaCode,string varCarriers,string varBillboardstype,DateTime varDateAdded,DateTime varDateModified)
		{
			PlanningLog item = new PlanningLog();
			
			item.MediaCode = varMediaCode;
			
			item.Carriers = varCarriers;
			
			item.Billboardstype = varBillboardstype;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varPlanningLogID,int? varMediaCode,string varCarriers,string varBillboardstype,DateTime varDateAdded,DateTime varDateModified)
		{
			PlanningLog item = new PlanningLog();
			
				item.PlanningLogID = varPlanningLogID;
				
				item.MediaCode = varMediaCode;
				
				item.Carriers = varCarriers;
				
				item.Billboardstype = varBillboardstype;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string PlanningLogID = @"PlanningLogID";
			 public static string MediaCode = @"MediaCode";
			 public static string Carriers = @"Carriers";
			 public static string Billboardstype = @"Billboardstype";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
						
		}

		#endregion
	}

}

